﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace POSPlus.PrintManager
{
	public partial class JobViewDialog : Form
	{
		private string _connectionString;
		private string _jobName;
		private DataTable _table;

		public JobViewDialog(string connectionString, string jobName)
		{
			InitializeComponent();
			_connectionString = connectionString;
			_jobName = jobName;
			_table = new DataTable();
			_table.Columns.Add("ID");
			_table.Columns.Add("Upc");
			_table.Columns.Add("Description");
			_table.Columns.Add("JobName");
			_table.Columns.Add("LocAisle");
			_table.Columns.Add("LocBlock");
			_table.Columns.Add("LocSeq");
			_table.Columns.Add("Type");

			ui_jobSummary.DataSource = _table;
		}

		private void JobViewDialog_Load(object sender, EventArgs e)
		{
			UpdateRows();
		}

		private void UpdateRows()
		{
			List<PrintManagerDisplay> displays =
				   PrintManagerDisplay.GetAll(_connectionString, _jobName);

			displays.Sort();

			_table.Clear();
			foreach (PrintManagerDisplay display in displays)
			{
				DataRow row = _table.NewRow();
				row["ID"] = display.DisplayID;
				row["Upc"] = display.Upc;
				row["Description"] = display.Description;
				row["JobName"] = display.JobName;
				row["LocAisle"] = display.LocAisle;
				row["LocBlock"] = display.LocBlock;
				row["LocSeq"] = display.LocSeq;
				row["Type"] = display.Type;
				_table.Rows.Add(row);
			}
			ui_jobSummary.DataSource = _table;
		}

		private void ui_removeButton_Click(object sender, EventArgs e)
		{
			List<int> ids = new List<int>();
			foreach (DataGridViewRow row in ui_jobSummary.SelectedRows)
			{
				ids.Add(Convert.ToInt32(row.Cells["ID"].Value));
			}

			PrintManagerDisplay.DeleteAll(_connectionString, ids.ToArray());
			UpdateRows();
		}
	}
}
